//
// Created by 32827 on 2023/11/15.
//

#ifndef YZFRAME_YZF_H
#define YZFRAME_YZF_H
#include "yzfdef.h"
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define YZF_ON 1
#define YZF_OFF 0
#define YZF_NULL 0U
#define YZF_REGV32 *( volatile uint32_t *)
#define YZF_REGV16 *( volatile uint16_t *)
#define YZF_REGV8 *( volatile uint8_t *)
#define YZF_ADD |=
#define YZF_DEL &=~
#define YZF_SET =
#define YZF_SETBIT(reg,x,v) reg YZF_SET ((reg&~YZF_BIT(x))|v*YZF_BIT(x))
#define YZF_BIT(x) (1UL<<(x))

#ifdef USE_HAL_DRIVER
#define YZF_HAL YZF_ON
#endif

#define YZF_SPI_POINTER volatile uint32_t *

#define YZF_NULL_PTR 0
    enum YZF_BOOL{
        YZF_FALSE = 0,
        YZF_TRUE = 1
    };

    enum YZF_STATUS{
        YZF_OK=0,
        YZF_ERROR,          ///未知错误
        YZF_NOT_INIT,       ///成员变量未初始化
        YZF_NOT_FOUND,      ///所选参数/配置未找到
        YZF_CRC_ERROR,      ///CRC校验错误
        YZF_CLOCK_NOT_READY, ///时钟未就绪
        YZF_HANDLER_NOT_FINISH,  ///处理函数未结束
        YZF_NOTHING          ///空闲
    };
    typedef enum YZF_STATUS YZF_RESULT;
    typedef enum YZF_BOOL YZF_BOOL;

    void YZF_ERROR_HANDLE(YZF_RESULT error);


#if YZF_CHECK
#define YZF_CHECK_PARAM(n) if((int)n==YZF_NULL){YZF_ERROR_HANDLE(YZF_NOT_INIT);return 1;};
#define YZF_CHECK_RETURN(n) if(n!=YZF_OK){YZF_ERROR_HANDLE(n);};
#else
#define YZF_CHECK_PARAM(n) ;
#define YZF_CHECK_RETURN(n) n
#endif

#ifdef __cplusplus
}
#endif
#endif //YZFRAME_YZF_H
